/**
 * The SimpleButton user-interface component and tag conversor class
 * @class syslib.ui.SimpleButton
 * @author Gabriel Ricci
 */
syslib.ui.SimpleButton = __class(syslib.ui.VisualTag, 
/**
 * @lends syslib.ui.SimpleButton
 */
{
	// class attributes
	id : "",
	title : "",  
	name : "", 
	
	prepare : function(element){
		// clear the attributes
		this.id = "";
		this.title = "";
		  
		// load the style
		syslib.loadStyleForComponent("simplebutton");

		// set some important information
		this.id = (__valid(this.__attributes.id)) ? this.__attributes.id : syslib.element.generateID();
		this.title = (__valid(this.__attributes.title)) ? this.__attributes.title : "Untitled SimpleButton";
		this.name = (__valid(this.__attributes.name)) ? this.__attributes.name : this.id;
		
		// return
		return true;
	},

	execute : function(){
		// create the attributes of the main objectcount
		var attributes = syslib.object.extend(this.__attributes, {
			"id" : this.id, 
			"class" : "simplebutton-container-normal"
		});

		// create the json structure
		elemtJSON = ["span", attributes,
			this.__innerHTML, 
			["input", {"type" : "hidden", "name" : this.name, "value" : this.title, "innerName" : "hiddenInput"}]
		];

		// create the element
		var button = this.createDOM(elemtJSON);

		// return
		return button;
	},

	finalize : function(){
		// create the events
		syslib.event.listen("mouseover", this.__element, function(){
			this.__element.className = "simplebutton-container-over";
		}.applyTo(this));
		
		syslib.event.listen("mouseout", this.__element, function(){
			this.__element.className = "simplebutton-container-normal";
		}.applyTo(this));
		
		syslib.event.listen("mousedown", this.__element, function(){
			this.__element.className = "simplebutton-container-clicked";
		}.applyTo(this));
		syslib.event.listen("mouseup", this.__element, function(){ 
			this.__element.className = "simplebutton-container-over";
		}.applyTo(this));
	}, 
	
	onEnterBody : function(){
		// add the form reference to the main element
		if(__valid(this.__refs.hiddenInput.form)){
			this.__element.form = this.__refs.hiddenInput.form;
		}
	}
});